package com.example.myapplication.util;

import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

//最简单 OkHttp 封装类 1.0
public class OkHttpUtil {
    public  static String headUrl = "http://192.168.0.128:8081";

    private static OkHttpClient okHttp = new OkHttpClient();

    //get请求
    public static void okGet(String url, Callback callback){
        Request build = new Request.Builder().url(headUrl + url).build();
        okHttp.newCall(build).enqueue(callback);
    }
    //post请求
    public static void okPost(String url, String s, Callback callback){
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),s);
        Request build = new Request.Builder().url(headUrl + url).post(requestBody).build();
        okHttp.newCall(build).enqueue(callback);
    }



}
